import React, { Fragment } from 'react'
import {
  View,
  StyleSheet,
  Text,
  Animated,
  FlatList
} from 'react-native'
import { ScaleS, ScaleT, IS_IOS, NAVIGATIONBAR_HEIGHT, IS_IPHONEX, WIDTH } from 'src/utils/ScreenUtil'
import BasePage from 'src/pageP/base/base-page/index'
import CustomImage from 'src/components/image/CustomImage'
import CustomButton from 'src/components/button/CustomButton'
import { ServiceTelephone, ImageHost } from 'src/config/index'
import {
  recommendPost,
  updateJobStatus,
  delJobHunting,
  delEducation,
  delWork,
  delImg,
  insertImg,
  liveCountToC
} from 'src/utils/RequestAPI'
import { CustomCallPhone } from 'src/utils/PermissionsUtil'
import { isEmptyObjectFn, isArrayFn } from 'src/utils/JSTypeUtil'
import { CommonToast, DismissLoading, ShowLoading } from 'src/utils/ToastUtil'

/* redux */
import { connect } from 'react-redux'
import {
  DO_REQUEST_MAIN_PAGE_C_ACTION,
  DO_REQUEST_MY_CENTER_NUMBERS_ACTION,
  UPDATE_USER_ARCHIVE_EDUCATION_ACTION,
  UPDATE_USER_ARCHIVE_WORK_ACTION,
  UPDATE_USER_ARCHIVE_IMG_ACTION
} from './store/action'
import { DO_REQUEST_USERINFO_C_ACTION } from 'src/store/actions/userinfo'
import { unloginDefaultPortrait, getUserAvatorLocalC, getJobStatus, iosAppFilter } from 'src/utils/ConfigUtil'
import AnimatedNaviBar, { MARGINTOP } from 'src/pageB/main/main-page/components/AnimatedNaviBar'
import DefaultImage from '../../../components/image/DefaultImage'
import { TabBar, TabView } from 'react-native-tab-view'
import ActionSheetModal2 from 'src/components/modal/ActionSheetModal2'
import { jobStatusArr } from 'utils/ConfigUtil'
import { UPDATE_MAIN_PAGE_C_ACTION } from '@/pageC/mine/mine-page/store/action'
import ShareBtn from 'src/components/button/ShareBtn'
import { shareToWXMiniProgram } from 'src/utils/PayUtil'
import JobHuntingOperateModel from '@/components/modal/JobHuntingOperateModel'
import DealJobHuntingModal from '@/components/modal/DealJobHuntingModal'
import { showModal, showImageViewerModal, showTipModal, showSelectModal } from 'src/utils/ModalUtil'
import { openCamera, multipleAlums } from 'src/utils/ImagePickerUtil'
import { uploadImgs } from 'src/utils/ImageUploadUtil'
import { ONE_PIXEL } from '@/utils/ScreenUtil'
import SchoolManage from './components/SchoolManage'
import ResumeComponent from 'src/components/resume-component/index'

const mapActiontoProps = dispatch => ({
  doRequestUserInfoC (payload) {
    const promise = DO_REQUEST_USERINFO_C_ACTION(payload)
    dispatch(promise)
    return promise.payload
  },
  doRequestMainPage (...payload) {
    const promise = DO_REQUEST_MAIN_PAGE_C_ACTION(...payload)
    dispatch(promise)
    return promise.payload
  },
  doRequestMyCenterNumbers (payload) {
    const promise = DO_REQUEST_MY_CENTER_NUMBERS_ACTION(payload)
    dispatch(promise)
    return promise.payload
  },
  updateMainPageC (payload) {
    dispatch(UPDATE_MAIN_PAGE_C_ACTION(payload))
  },
  updateUserArchiveEducation (payload) {
    dispatch(UPDATE_USER_ARCHIVE_EDUCATION_ACTION(payload))
  },
  updateUserArchiveWork (payload) {
    dispatch(UPDATE_USER_ARCHIVE_WORK_ACTION(payload))
  },
  updateUserArchiveImg (payload) {
    dispatch(UPDATE_USER_ARCHIVE_IMG_ACTION(payload))
  }
})

@connect(
  ({ userinfo, CMineCenterStore, landmark }) => ({
    userinfo,
    userinfoC: userinfo.C,
    ...CMineCenterStore,
    landmark
  }),
  mapActiontoProps
)
class CMinePage extends BasePage {
  constructor (props) {
    super(props)
    this.selectModalConfig = {
      selectArr: [
        {
          label: '相册上传'
        },
        {
          label: '拍照上传'
        }],
      titleText: '添加照片',
      onCancel: this._selectModalCancel,
      selectClick: this._selectModalClick
    }
    this.state = {
      viewRef: null,
      recommendJob: [],
      scrollY: new Animated.Value(0),
      index: 0,
      routes: [
        { key: 'resume', title: '简历' },
        { key: 'schoolEnrollment', title: '校招' }
        // { key: 'alumnus', title: '校友' }
      ],
      jobIntentionVisible: false,
      modalDealState: '',
      modalShowStatus: '',
      modelActiveIndex: 0,
      initIndex: 0,
      dataPhotoArr: [],
      checkedIds: [],
      dataApplyLive: 0,
      dataCollectLive: 0,
      dataPostLive: 0
    }
  }

  componentDidMount () {
    console.log('componentDidMount')
  }

  componentWillFocus (payload) {
    console.log('componentWillFocus')
    const {
      userinfo: { userId },
      doRequestUserInfoC,
      doRequestMainPage,
      doRequestMyCenterNumbers
    } = this.props
    if (userId) {
      doRequestUserInfoC({ params: { userId } }).finally(() => {
        const { userinfo: { C: { userId: userIdC } }, archiveInfo: { archiveId } = {} } = this.props
        if (userIdC) {
          doRequestMainPage({ params: { userId } }).then(() => {
            this.setState({
              dataPhotoArr: this._transformDataArr()
            })
          })
          doRequestMyCenterNumbers({ type: 'C', userId, archiveId })
          this._getSchoolData()
        }
      })
    } else {
      this.setState({
        dataPhotoArr: []
      })
    }

    this._recommendPost()
  }

  /**
   * 职位推荐
   * */
  _recommendPost = () => {
    const { landmark: { cityName } } = this.props
    recommendPost({
      params: {
        city: cityName
      }
    }).then(data => {
      console.info(data)
      this.setState({
        recommendJob: iosAppFilter(data.data, ['name'])
      })
    })
  }

  componentDidUpdate (prevProps, prevState) {
  }

  _getSchoolData = () => {
    // 获取校招数据
    liveCountToC().then(({ data }) => {
      this.setState({
        dataApplyLive: data.apply,
        dataCollectLive: data.collection,
        dataPostLive: data.send
      })
    })
  }

  updateUserinfoC = () => {
    const {
      userinfo: { userId },
      doRequestUserInfoC
    } = this.props
    !!userId &&
      doRequestUserInfoC({ params: { userId } }).then(res => {
        // todo
        if (isEmptyObjectFn(res)) {
          CommonToast('请完善个人信息').then(() => {
            this.props.navigation.navigate(`CFirstUserInfo`)
          })
        }
      })
  }

  childRender () {
    const {
      userinfo: { userId, role },
      userinfoC,
      userArchiveModel,
      myCenterNumbers
    } = this.props
    const { userName } = userinfoC
    const { jobIntentionVisible } = this.state
    return (
      <Fragment>
        <Animated.ScrollView
          style={styles.container}
          showsVerticalScrollIndicator={false}
          onScroll={
            Animated.event([{
              nativeEvent: { contentOffset: { y: this.state.scrollY } }
            }], {
              useNativeDriver: IS_IOS
            })
          }>
          <View style={styles.shareBar}>
            <ShareBtn onPress={this._onShared} />
          </View>
          <View style={styles.titleView}>
            <View style={styles.titleLeft}>
              <CustomButton
                style={styles.titleCenterView}
                onPress={this._jumpBaseMessage}
              >
                <Text style={styles.titleCenterName}>
                  {userinfoC.userId
                    ? userinfoC.userName
                    : '无名之辈'}
                </Text>
              </CustomButton>
              <CustomButton style={styles.jobHuntingView} onPress={this.showSelect}>
                {getJobStatus(userArchiveModel.jobStatus) === '寻找工作' && <CustomImage
                  style={styles.jobHuntingImg}
                  source={require('@/imgC/userinfo/hunting_find.png')}
                />}
                {getJobStatus(userArchiveModel.jobStatus) === '考虑机会' && <CustomImage
                  style={styles.jobHuntingImg}
                  source={require('@/imgC/userinfo/hunting_think.png')}
                />}
                <Text style={styles.jobHuntingText}>{getJobStatus(userArchiveModel.jobStatus) || '太懒了，还没有求职状态…'}</Text>
              </CustomButton>
            </View>
            <CustomButton
              style={styles.titlePortraitBtn}
              onPress={this._jumpAvator}
            >
              {
                userinfoC.userId ? (
                  <DefaultImage
                    style={styles.titlePortraitImg}
                    source={{ uri: userinfoC.userAvator }}
                    errorSource={getUserAvatorLocalC(
                      userinfoC.gender,
                      userinfoC.userId
                    )}
                  />
                ) : (
                  <CustomImage style={styles.titlePortraitImg} source={unloginDefaultPortrait} />
                )
              }
            </CustomButton>
          </View>

          <View style={styles.infoContainer}>
            <View style={styles.infoContainerLeft}>
              <CustomButton style={styles.followInfo} onPress={this.goJobCollection}>
                <Text style={styles.followInfoTop}>{myCenterNumbers.postCollection || 0}</Text>
                <Text style={styles.followInfoBottom}>关注</Text>
              </CustomButton>
              <CustomButton style={styles.followInfo}>
                <Text style={styles.followInfoTop}>{myCenterNumbers.archiveCollection || 0}</Text>
                <Text style={styles.followInfoBottom}>被关注</Text>
              </CustomButton>
            </View>
            <View style={styles.infoContainerRight}>
              <CustomButton style={styles.followBtn} onPress={this._setBtnClick}>
                <CustomImage
                  source={require('@/imgC/userinfo/set_black.png')}
                />
              </CustomButton>
              <CustomButton style={styles.goChatBtn}>
                <Text style={styles.goChatBtnText}>更多</Text>
              </CustomButton>
            </View>
          </View>

          <TabView
            style={styles.tabView}
            navigationState={this.state}
            renderScene={this._renderScene}
            onIndexChange={this._onIndexChange}
            renderTabBar={this._renderTabBar}
            lazy={true}
            initialLayout={{
              height: 0,
              width: WIDTH
            }}
          />
        </Animated.ScrollView>
        <AnimatedNaviBar
          userName={userName || '无名之辈'}
          scrollY={this.state.scrollY}
          userNameClick={this._jumpBaseMessage}
          setBtnClick={this._setBtnClick}
          shareBtnClick={this._onShared}
          role={role}
        />

        <ActionSheetModal2
          visible={jobIntentionVisible}
          selectArr={jobStatusArr}
          onCancel={this.onCancel}
          selectClick={this.selectClick}
          onModalHide={this.onModalHide}
          titleText={'求职状态'}
        />
      </Fragment>

    )
  }

  _onShared = () => {
    const { userinfo: { userId }, userinfoC: { userName: title } } = this.props
    if (userId && title) {
      shareToWXMiniProgram({ title, shareUrl: `pages/person-detail/index?userId=${userId}&share=app` })
    }
  }

  showSelect = () => {
    !this._loginJump() && this.setState({
      jobIntentionVisible: true
    })
  }

  onCancel = () => {
    this.setState({
      jobIntentionVisible: false
    })
  }

  selectClick = () => {
    this.setState({
      jobIntentionVisible: false
    })
  }

  onModalHide = index => {
    if (!index) {
      return
    }
    index = index - 1
    const { userinfo: { userId }, userArchiveModel } = this.props
    const { id: archiveId } = userArchiveModel
    const params = {
      userId,
      archiveId,
      jobStatus: jobStatusArr[index].value
    }
    ShowLoading()
    updateJobStatus({ params }).then(() => {
      this.setState({
        jobIntentionVisible: false
      })
      this.props.updateMainPageC({
        userArchiveModel: {
          ...userArchiveModel,
          jobStatus: jobStatusArr[index].value
        }
      })
    }).finally(() => {
      DismissLoading()
    })
  }

  _loginJump = () => {
    const {
      userinfo: { userId, C: { userId: userIdC } = {} }
    } = this.props
    if (!userId) {
      this.props.navigation.navigate('OneLogin')
      return true
    }
    if (!userIdC) {
      this.props.navigation.navigate('CFirstUserInfo')
      return true
    }
  }

  _jumpAvator = () => {
    !this._loginJump() && this.props.navigation.navigate('CUserAvator')
  }

  _jumpBaseMessage = () => {
    !this._loginJump() && this.props.navigation.navigate('CUserInfoBasic')
  }

  _jumpSelfEvaluationPage = () => {
    !this._loginJump() &&
      this.props.navigation.navigate('CUserSelfEvalution', {
        title: '自我评价',
        desc: '*充分展现自我优势，让更多企业发现你',
        placeholder: '请输入自我评价',
        maxLength: 140,
        multiline: true,
        inputTextStyle: {
          minHeight: ScaleS(150)
        }
      })
  }

  _setBtnClick = () => {
    this.props.navigation.navigate('CSetPage')
  }

  goJobCollection = () => {
    !this._loginJump() && this.props.navigation.navigate('CJobCollection')
  }

  goCommunicationHistory = () => {
    !this._loginJump() && this.props.navigation.navigate('CCommunicationHistory')
  }

  _previewResume = () => {
    if (this._loginJump()) {
      return
    }
    const { jobHuntingModels = [], intro, educations = [], userArchiveWorkModels = [] } = this.props
    if (jobHuntingModels.length === 0) {
      CommonToast('请完善求职意愿')
      return
    }
    if (!intro) {
      CommonToast('请完善自我评价')
      return
    }
    if (educations.length === 0 && userArchiveWorkModels.length === 0) {
      CommonToast('请完善教育信息')
      return
    }
    this.props.navigation.navigate('CResumeDetail')
  }

  goSetting = () => {
  }

  _jumpIntentionPage = () => {
    if (!this._loginJump()) {
      const { jobHuntingModels } = this.props
      this.jobHuntingModel = showModal(
        <JobHuntingOperateModel
          dataArr={jobHuntingModels || []}
          type={'jobHunting'}
          addJobHunting={this._addJobHunting}
          editJobHunting={this._editJobHunting}
          deleteJobHunting={this._deleteJobHunting} />)
    }
  }

  _addJobHunting = () => {
    // 添加求职意向
    this.jobHuntingModel.close()
    // const callback = newJobIntention => {
    //   const { jobHuntingModels } = this.props
    //   this.props.updateMainPageC({
    //     jobHuntingModels: [...jobHuntingModels, newJobIntention]
    //   })
    // }
    this.props.navigation.navigate('CUserJobIntentionEdit', {
      jobIntention: {}
      // callback
    })
  }

  _editJobHunting = () => {
    // 编辑求职意向
    const { jobHuntingModels } = this.props
    this.jobHuntingModel.close(() => {
      this.dealJobHuntingModel = showModal(
        <DealJobHuntingModal
          dataStatus={'jobHunting'}
          dataArr={jobHuntingModels}
          modelActiveIndex={0}
          modalDealState={'edit'}
          onClickModelItem={this._onClickModelItem}
          onClickModelBtn={this._onClickModelBtn}
        />)
      this.setState({
        modalDealState: 'edit',
        modalShowStatus: 'jobHunting',
        modelActiveIndex: 0
      })
    })
  }

  _deleteJobHunting = () => {
    // 删除求职意向
    const { jobHuntingModels } = this.props
    this.jobHuntingModel.close(() => {
      this.dealJobHuntingModel = showModal(
        <DealJobHuntingModal
          dataStatus={'jobHunting'}
          dataArr={jobHuntingModels}
          modelActiveIndex={0}
          modalDealState={'delete'}
          onClickModelItem={this._onClickModelItem}
          onClickModelBtn={this._onClickModelBtn}
        />)
      this.setState({
        modalDealState: 'delete',
        modalShowStatus: 'jobHunting',
        modelActiveIndex: 0
      })
    })
  }

  _onClickModelItem = (index) => {
    // 点击弹窗item
    const { modalShowStatus } = this.state
    if (modalShowStatus === 'photo') {
      this.setState({
        checkedIds: index
      })
    } else {
      this.setState({
        modelActiveIndex: index
      })
    }
  }

  _onClickModelBtn = () => {
    // 点击弹窗按钮
    const { modelActiveIndex, modalDealState, modalShowStatus } = this.state
    switch (modalShowStatus) {
      case 'jobHunting':
        this.dealJobHuntingModel.close(() => {
          const { jobHuntingModels } = this.props
          const jobIntention = jobHuntingModels[modelActiveIndex]
          const callback = newJobIntention => {
            if (newJobIntention) {
              this.props.updateMainPageC({
                jobHuntingModels: jobHuntingModels.map(f => f.id === newJobIntention.id ? newJobIntention : f)
              })
            } else {
              this.props.updateMainPageC({
                jobHuntingModels: jobHuntingModels.filter(f => f.id !== jobIntention.id)
              })
            }
          }
          switch (modalDealState) {
            case 'edit':
              this.props.navigation.navigate('CUserJobIntentionEdit', {
                jobIntention,
                callback
              })
              break
            case 'delete':
              const {
                userinfoC: { userId }
              } = this.props

              /* 删除 */
              const params = {
                id: jobIntention.id,
                userId
              }
              ShowLoading()
              delJobHunting({ params }).then(res => {
                !!callback && callback()
              }).finally(() => {
                DismissLoading()
              })
              break
            default:
              CommonToast('其他操作')
              break
          }
        })
        break
      case 'education':
        this.dealEducationModel.close(() => {
          const { educations } = this.props
          const educationsItem = educations[modelActiveIndex]
          switch (modalDealState) {
            case 'edit':
              this.props.navigation.navigate('CEducationInfoManager', {
                education: educationsItem,
                showDelete: educations.length > 1
              })
              break
            case 'delete':
              const { userinfoC: { userId } } = this.props
              const params = {
                id: educationsItem.id,
                userId
              }
              delEducation({ params }).then(() => {
                CommonToast('删除成功')
                const educationsNew = educations.filter((item) => {
                  return item.id !== educationsItem.id
                })
                this.props.updateUserArchiveEducation({
                  educations: educationsNew
                })
              })
              break
            default:
              CommonToast('其他操作')
              break
          }
        })
        break
      case 'work':
        this.dealWorkExperienceModel.close(() => {
          const { userArchiveWorkModels } = this.props
          const workItem = userArchiveWorkModels[modelActiveIndex]
          switch (modalDealState) {
            case 'edit':
              this.props.navigation.navigate('CWorkExperienceManager', {
                workExperience: workItem,
                showDelete: userArchiveWorkModels.length > 1
              })
              break
            case 'delete':
              const { userinfoC: { userId } } = this.props
              const params = {
                id: workItem.id,
                userId
              }
              delWork({ params }).then(() => {
                CommonToast('删除成功')
                const userArchiveWorkModelsNew = userArchiveWorkModels.filter((item) => {
                  return item.id !== workItem.id
                })
                this.props.updateUserArchiveWork({
                  userArchiveWorkModels: userArchiveWorkModelsNew
                })
              })
              break
            default:
              CommonToast('其他操作')
              break
          }
        })
        break
      case 'photo':
        this.dealPhotoModel.close(() => {
          const { checkedIds, dataPhotoArr } = this.state
          const { userinfoC, updateUserArchiveImg } = this.props
          delImg({
            params: {
              userId: userinfoC.userId,
              ids: checkedIds.join(',')
            }
          }).then(() => {
            CommonToast('照片删除成功')
            const remainDatas = dataPhotoArr.reduce((newDataArr, currentValue) => {
              return checkedIds.includes(currentValue.id) ? newDataArr : newDataArr.concat(currentValue)
            }, [])
            this.setState({
              checkedIds: [],
              dataPhotoArr: remainDatas
            })
            updateUserArchiveImg({
              userArchiveImgModels: remainDatas
            })
          })
        })
        break
    }
  }

  _jumpEducationPage = () => {
    // 操作教育信息
    if (this._loginJump()) return
    const { educations } = this.props
    this.educationModel = showModal(
      <JobHuntingOperateModel
        type={'education'}
        dataArr={educations || []}
        addJobHunting={this._addEducation}
        editJobHunting={this._editEducation}
        deleteJobHunting={this._deleteEducation} />)
  }

  _addEducation = () => {
    // 增加教育信息
    this.educationModel.close()
    const { navigation, educations } = this.props
    // if (!!educations && educations.length > 0) {
    //   navigation.navigate('CEducationInfo')
    // } else {
    navigation.navigate('CEducationInfoManager')
    // }
  }

  _editEducation = () => {
    // 修改教育信息
    const { educations } = this.props
    this.educationModel.close(() => {
      this.dealEducationModel = showModal(
        <DealJobHuntingModal
          dataArr={educations}
          dataStatus={'education'}
          modelActiveIndex={0}
          modalDealState={'edit'}
          onClickModelItem={this._onClickModelItem}
          onClickModelBtn={this._onClickModelBtn}
        />)
      this.setState({
        modalDealState: 'edit',
        modalShowStatus: 'education',
        modelActiveIndex: 0
      })
    })
  }

  _deleteEducation = () => {
    // 删除教育信息
    const { educations } = this.props
    this.educationModel.close(() => {
      this.dealEducationModel = showModal(
        <DealJobHuntingModal
          dataArr={educations}
          dataStatus={'education'}
          modelActiveIndex={0}
          modalDealState={'delete'}
          onClickModelItem={this._onClickModelItem}
          onClickModelBtn={this._onClickModelBtn}
        />)
      this.setState({
        modalDealState: 'delete',
        modalShowStatus: 'education',
        modelActiveIndex: 0
      })
    })
  }

  _jumpWorkExperience = () => {
    if (this._loginJump()) return
    const { userArchiveWorkModels } = this.props
    this.workExperienceModel = showModal(
      <JobHuntingOperateModel
        type={'work'}
        dataArr={userArchiveWorkModels || []}
        addJobHunting={this._addWorkExperience}
        editJobHunting={this._editWorkExperience}
        deleteJobHunting={this._deleteWorkExperience} />)
  }

  _addWorkExperience = () => {
    // 添加工作经验
    this.workExperienceModel.close()
    const { navigation, userArchiveWorkModels } = this.props
    // if (!!userArchiveWorkModels && userArchiveWorkModels.length > 0) {
    //   navigation.navigate('CWorkExperience')
    // } else {
    navigation.navigate('CWorkExperienceManager')
    // }
  }

  _editWorkExperience = () => {
    // 修改工作经验
    const { userArchiveWorkModels } = this.props
    this.workExperienceModel.close(() => {
      this.dealWorkExperienceModel = showModal(
        <DealJobHuntingModal
          dataStatus={'work'}
          dataArr={userArchiveWorkModels}
          modelActiveIndex={0}
          modalDealState={'edit'}
          onClickModelItem={this._onClickModelItem}
          onClickModelBtn={this._onClickModelBtn}
        />)
      this.setState({
        modalDealState: 'edit',
        modalShowStatus: 'work',
        modelActiveIndex: 0
      })
    })
  }

  _deleteWorkExperience = () => {
    // 删除工作经验
    const { userArchiveWorkModels } = this.props
    this.workExperienceModel.close(() => {
      this.dealWorkExperienceModel = showModal(
        <DealJobHuntingModal
          dataStatus={'work'}
          dataArr={userArchiveWorkModels}
          modelActiveIndex={0}
          modalDealState={'delete'}
          onClickModelItem={this._onClickModelItem}
          onClickModelBtn={this._onClickModelBtn}
        />)
      this.setState({
        modalDealState: 'delete',
        modalShowStatus: 'work',
        modelActiveIndex: 0
      })
    })
  }

  /**
   * 操作相册
   * @returns {*}
   * @private
   */
  _jumpMyPhoneAlbums = () => {
    if (this._loginJump()) return
    const { userArchiveImgModels } = this.props
    this.photoModel = showModal(
      <JobHuntingOperateModel
        type={'photo'}
        dataArr={userArchiveImgModels || []}
        addJobHunting={this._addPhoto}
        deleteJobHunting={this._deletePhoto} />)
  }

  _addPhoto = () => {
    // !this._loginJump() && this.props.navigation.navigate('CMyPhotoAlbums')
    this.photoModel.close(() => {
      this._toggleSelectModal(true)
    })
  }

  _deletePhoto = () => {
    // 删除相册
    const { userArchiveImgModels } = this.props
    this.photoModel.close(() => {
      this.dealPhotoModel = showModal(
        <DealJobHuntingModal
          dataStatus={'photo'}
          dataArr={userArchiveImgModels}
          modelActiveIndex={0}
          modalDealState={'delete'}
          onClickModelItem={this._onClickModelItem}
          onClickModelBtn={this._onClickModelBtn}
        />)
      this.setState({
        modalDealState: 'delete',
        modalShowStatus: 'photo',
        modelActiveIndex: 0
      })
    })
  }

  _toggleSelectModal = (selectModalShow, callBack) => {
    if (selectModalShow) {
      this.selectModal = showSelectModal(this.selectModalConfig)
    } else {
      if (this.selectModal) {
        this.selectModal.close(() => {
          callBack && callBack()
        })
      }
    }
  }

  _selectModalCancel = () => {
    this._toggleSelectModal(false)
  }

  _selectModalClick = index => {
    switch (index) {
      case 0:
        this.selectModal.close(() => {
          multipleAlums().then((images) => {
            this._addImage(images)
          })
        })
        break
      case 1:
        this.selectModal.close(() => {
          openCamera({
            width: 750, height: 750
          }).then((image) => {
            console.info(image)
            this._addImage(image)
          })
        })
        break
      default:
        this.selectModal.close()
    }
  }

  _addImage = (img) => {
    if (isArrayFn(img)) {
      this._uploadImages(img)
    } else {
      this._uploadImages([img])
    }
  }

  _uploadImages = (images) => {
    ShowLoading()
    uploadImgs({ localImgs: images }).then((result) => {
      if (result.length > 0) {
        this._uploadImage(result)
      } else {
        CommonToast('图片上传失败')
        DismissLoading()
      }
    })
  }

  _uploadImage = (userArchiveImgModels = []) => {
    const { userinfoC, updateUserArchiveImg } = this.props
    insertImg({
      params: {
        userId: userinfoC.userId,
        imgUrls: userArchiveImgModels.join(',')
      }
    }).then((data) => {
      const newDataArr = data.data ? data.data.map((item) => {
        item.url = ImageHost + item.imgUrl
        return item
      }) : []
      this.setState({
        dataPhotoArr: newDataArr
      })
      updateUserArchiveImg({
        userArchiveImgModels: newDataArr
      })
      DismissLoading()
    }).catch((data) => {
      console.info(data)
      DismissLoading()
    })
  }

  _showImageViewer = () => {
    const { dataPhotoArr, initIndex } = this.state
    this.imgageViewerModal = showImageViewerModal({
      onClose: this._closeImageViewerModal,
      images: dataPhotoArr,
      initIndex
    })
  }

  _closeImageViewerModal = () => {
    if (this.imgageViewerModal) {
      this.imgageViewerModal.close()
    }
  }

  _transformDataArr = () => {
    const { userArchiveImgModels } = this.props
    const returnData = userArchiveImgModels.map((item) => {
      item.url = ImageHost + item.imgUrl
      return item
    })
    return returnData
  }

  _imgItemClick = ({ item, index }) => {
    this.setState({
      initIndex: index
    }, () => {
      this._showImageViewer()
    })
  }

  _keyExtractor = item => item.id
  // 操作相册结束

  _callPhone = () => {
    CustomCallPhone(ServiceTelephone)
  }

  /**
   * 渲染每一个屏
   * @param route
   * @param jumpTo
   * @returns {*}
   * @private
   */
  _renderScene = ({ route, jumpTo }) => {
    const { index, routes } = this.state
    switch (route.key) {
      case 'resume':
        return routes[index].key === 'resume' ? this._renderResumeComponent() : null
      case 'schoolEnrollment':
        return routes[index].key === 'schoolEnrollment' ? this._renderSchoolEnrollmentComponent() : null
      case 'alumnus':
        return routes[index].key === 'alumnus' ? this._renderalumnusComponent() : null
    }
  }

  /**
   * 渲染简历
   * @returns {*}
   * @private
   */
  _renderResumeComponent = () => {
    const {
      jobHuntingModels, userArchiveWorkModels, educations, intro
    } = this.props
    const { dataPhotoArr } = this.state
    return <ResumeComponent
      jobHuntingModels={jobHuntingModels}
      userArchiveWorkModels={userArchiveWorkModels}
      educations={educations}
      intro={intro}
      dataPhotoArr={dataPhotoArr}
      jumpIntentionPage={this._jumpIntentionPage}
      jumpSelfEvaluationPage={this._jumpSelfEvaluationPage}
      jumpEducationPage={this._jumpEducationPage}
      jumpWorkExperience={this._jumpWorkExperience}
      jumpMyPhoneAlbums={this._jumpMyPhoneAlbums}
      keyExtractor={this._keyExtractor}
    />
  }

  /**
   * 渲染校招
   * @returns {*}
   * @private
   */
  _renderSchoolEnrollmentComponent = () => {
    const { dataApplyLive, dataCollectLive, dataPostLive } = this.state
    return <SchoolManage
      schoolClick={this._schoolClick}
      dataApplyLive={dataApplyLive}
      dataCollectLive={dataCollectLive}
      dataPostLive={dataPostLive}
    />
  }

  /**
   * 渲染校友
   * @returns {*}
   * @private
   */
  _renderalumnusComponent = () => {
    return (
      <Fragment></Fragment>
    )
  }

  /**
   * 切换标签
   * @param index
   * @private
   */
  _onIndexChange = (index) => {
    this.setState({ index })
  }

  /**
   * 渲染tabBar
   * @param props
   * @returns {*}
   * @private
   */
  _renderTabBar = (props) => {
    const { navigationState: { index, routes } } = props
    return (
      <View style={styles.tabContainer}>
        <CustomButton style={styles.tabItem} onPress={this._tabBarClick} params={{ props, key: routes[0].key }}>
          <Text style={[styles.tabItemText, index === 0 && styles.tabItemActive]}>{routes[0].title}</Text>
        </CustomButton>
        <View style={styles.tabLine}></View>
        <CustomButton style={styles.tabItem} onPress={this._tabBarClick} params={{ props, key: routes[1].key }}>
          <Text style={[styles.tabItemText, index === 1 && styles.tabItemActive]}>{routes[1].title}</Text>
        </CustomButton>
        {/* <View style={styles.tabLine}></View>
        <CustomButton style={styles.tabItem} onPress={this._tabBarClick} params={{ props, key: routes[2].key }}>
          <Text style={[styles.tabItemText, index === 2 && styles.tabItemActive]}>{routes[2].title}</Text>
        </CustomButton> */}
      </View>
    )
  }

  _tabBarClick = ({ props, key }) => {
    const { jumpTo, navigationState: { index, routes } } = props
    jumpTo(key)
  }

  _schoolClick = ({ index, liveKey }) => {
    switch (liveKey) {
      case 'subscribe':
        !this._loginJump() && this.props.navigation.navigate('LiveSubscribe', {
          liveKey,
          liveIndex: 0
        })
        break
      case 'collection':
        !this._loginJump() && this.props.navigation.navigate('LiveSubscribe', {
          liveKey,
          liveIndex: 1
        })
        break
      case 'resume':
        !this._loginJump() && this.props.navigation.navigate('LiveSubscribe', {
          liveKey,
          liveIndex: 2
        })
        break
    }
  }
}

export default CMinePage
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#FFFFFF'
  },
  shareBar: {
    paddingTop: IS_IPHONEX ? ScaleS(52) : ScaleS(32),
    // paddingTop: ScaleS(52),
    flexDirection: 'row',
    justifyContent: 'flex-end',
    marginHorizontal: ScaleS(20)
  },
  titleView: {
    marginTop: ScaleS(20),
    flexDirection: 'row',
    marginHorizontal: ScaleS(20)
  },
  titlePortraitBtn: {},
  titlePortraitImg: {
    width: ScaleS(90),
    height: ScaleS(90),
    resizeMode: 'cover',
    borderRadius: ScaleS(45)
  },
  titleLeft: {
    flex: 1,
    flexDirection: 'column',
    paddingTop: ScaleS(15)
  },
  titleCenterView: {
    // alignItems: 'flex-start'
  },
  jobHuntingView: {
    flexDirection: 'row',
    marginTop: ScaleS(15)
  },
  jobHuntingImg: {
    marginRight: ScaleS(5)
  },
  jobHuntingText: {
    fontSize: ScaleS(14),
    color: '#3C3C3C'
  },
  titleCenterName: {
    color: '#3C3C3C',
    fontSize: ScaleT(22),
    fontWeight: '900'
  },
  titleRightImg: {
    width: 26,
    height: 26,
    marginTop: 3
  },
  titleInfo: {
    flexDirection: 'row',
    paddingHorizontal: ScaleS(20),
    marginTop: ScaleS(36),
    justifyContent: 'space-between'
  },
  infoContainer: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'flex-end',
    justifyContent: 'space-between',
    marginTop: ScaleS(50),
    marginHorizontal: ScaleS(20),
    paddingBottom: ScaleS(19),
    borderBottomColor: '#f1f1f1',
    borderBottomWidth: ONE_PIXEL,
    borderStyle: 'solid'
  },
  infoContainerLeft: {
    flexDirection: 'row',
    alignItems: 'center'
  },
  followInfo: {
    flexDirection: 'column',
    alignItems: 'center',
    marginRight: ScaleS(40)
  },
  followInfoTop: {
    fontSize: ScaleT(20),
    fontWeight: 'bold',
    color: '#3C3C3C'
  },
  followInfoBottom: {
    fontSize: ScaleT(11),
    color: '#9E9E9E',
    marginTop: ScaleS(5)
  },
  infoContainerRight: {
    flexDirection: 'row'
  },
  followBtn: {
    width: ScaleS(50),
    height: ScaleS(30),
    backgroundColor: 'rgba(74,74,74,1)',
    borderRadius: ScaleS(4),
    justifyContent: 'center',
    alignItems: 'center',
    marginRight: ScaleS(10)
  },
  followBtnText: {
    fontSize: ScaleT(18),
    fontWeight: 'bold',
    color: '#fff'
  },
  goChatBtn: {
    width: ScaleS(70),
    height: ScaleS(30),
    backgroundColor: 'rgba(255,228,0,1)',
    borderRadius: ScaleS(4),
    justifyContent: 'center',
    alignItems: 'center'
  },
  goChatBtnText: {
    fontSize: ScaleT(12),
    fontWeight: '500',
    color: '#000'
  },
  tabContainer: {
    flexDirection: 'row',
    paddingHorizontal: ScaleS(20),
    marginTop: ScaleS(22),
    // marginBottom: ScaleS(20),
    alignItems: 'center'
  },
  tabItem: {
    // marginRight: ScaleS(29)
  },
  tabLine: {
    width: ONE_PIXEL,
    height: ScaleS(10),
    backgroundColor: '#d5d5d5',
    marginHorizontal: ScaleS(20)
  },
  tabItemText: {
    fontSize: ScaleT(13),
    fontWeight: '500',
    color: '#999999'
  },
  tabItemActive: {
    color: '#3C3C3C',
    fontWeight: '900'
  }
})
